﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microhard.Permission.Interface;
using Microhard.WarehouseInsp.Buz.Models;
using Microhard.WarehouseInsp.Buz.Interfaces;
using Microsoft.Practices.Unity;
using Microhard.Workflow;
using Microhard.WarehouseInsp.Buz.JHWorkflow;
using FluentValidation.Mvc;
using Microhard.Permission.MVCFilter;
using Microhard.WebUI.Models;
using Microhard.Core;
using Microhard.JHWorkflowTrans;
using Telerik.Web.Mvc;
using Microhard.Core.DBUtility;
using Microhard.WarehouseInsp.Buz.Impls;

namespace Microhard.WarehouseInsp.WebUI.Areas.WarehouseInsp.Controllers
{
    public class SupProjectController : MicroHardBaseController<SupProjectModel>
    {
        private ISupProject _prj = null;
        [Dependency]
        public ISupProject Prj
        {
            set
            {
                base._repository = _prj = value;
            }
            get
            {
                return _prj;
            }

        }


        [MVCFilterAtrForCustomeDataPermission(typeof(ProjectMngScopeImpl), DataScopeactionParameterName = "scope", Order = 3)]//数据权限验证
        public override ActionResult Update(Guid identity, ScopeResult scope)
        {
            return base.Update(identity, scope);
        }

        [MVCFilterAtrForCustomeDataPermission(typeof(ProjectMngScopeImpl), DataScopeactionParameterName = "scope", Order = 3)]//数据权限验证
        public override ActionResult SaveUpdate([CustomizeValidator(RuleSet = "Update")]SupProjectModel model, ScopeResult scope)
        {
            return base.SaveUpdate(model, scope);
        }

        [MVCFilterAtrForCustomeDataPermission(typeof(ProjectMngScopeImpl), DataScopeactionParameterName = "scope", Order = 3)]//数据权限验证
        public override ActionResult Delete(List<Guid> identities, ScopeResult scope)
        {
            return base.Delete(identities, scope);
        }

        [MVCFilterAtrForCustomeDataPermission(typeof(ProjectMngScopeImpl), DataScopeactionParameterName = "scope", Order = 3)]//数据权限验证
        public override ActionResult _AjaxViewDetail(Guid identity, ScopeResult scope)
        {
            return base._AjaxViewDetail(identity, scope);
        }

        [StartJHWorkflowTransFilter("SupPrjApply", typeof(SupProjectTransJDImpl), typeof(JHGetConfig), Order = 4)]
        public override ActionResult StartC6Workflow(Guid identity, string approvers, ScopeResult scope, bool isWorkflowStarted)
        {
            return base.StartC6Workflow(identity, approvers, scope, isWorkflowStarted);
        }

        [MVCFilterAtrForLogon()]
        public ActionResult GetSupProjectList(AttriubteOfSelectList ctrAttr, Core.DBUtility.ScopeResult scope)
        {
            ISupProject temp = IoC.Resolve<ISupProject>();
            temp.scope = scope;
            var comp = temp.Query(null);
            ctrAttr.Data = comp.Select(r => new SelectData
            {
                ID = r.ProjectID.ToString(),
                Name = r.Name
            }).ToList();
            return View("SelectList", ctrAttr);
        }


    }
}
